<template>
	<tm-fullView>
		<tm-menubars :title="$t('申请加为好友')" iconColor="white" :showback="true"/>
		<view style="padding-top: 30rpx;background-color: #fff;" :class="{'black':isBlack}">
			<tm-input :vertical="true" :height="120" :maxlength="200"  :border-bottom="false" :placeholder="$t('请输入申请理由')"  input-type="textarea" v-model="reason" bg-color="grey-lighten-5" clear></tm-input>
		</view>
		<view>
			<tm-button :loading="loading" class="ma-30" @click="applyClick" theme="grey-darken-2" block>{{$t('立即申请')}}</tm-button>
		</view>
		
	</tm-fullView>
</template>

<script>
	import FriendApi from '@/api/friend.js'
	export default {
		data() {
			return {
				reason:'',
				userId:'',
				loading:false
			}
		},
		onLoad(options) {
			this.userId=options.userId
		},
		methods: {
			async applyClick(){
				let self=this
				if(self.userId==''){
					return
				}
				if(self.reason==''){
					self.toast('请输入申请理由')
				}
				let data={toId:self.userId,reason:self.reason}
				self.loading=true
				let res=await FriendApi.apply(data)
				self.loading=false
				self.toast(res.msg)
				if(res.code==200){
					setTimeout(()=>{
						uni.switchTab({
							url:'/pages/index/index'
						})
					},1000)
					
				}
			}
		}
	}
</script>

<style>

</style>
